<template>
  <view class="help-container">
	  <uni-collapse ref="collapse" v-model="activeVal">
	  	<uni-collapse-item title="通知设置" >
	  	<view class="content">
	<!-- 站内通知 -->
	<uni-section class="mb-10" title="站内通知" sub-title="若关闭，进行文件签署、文件签署完成时，将不通过站内信的方式向您发送通知信息。" style="margin-top: 0;">
		<template v-slot:right>
			<span @click="handleSysNoticeStatusChange(notice)">
				<switch color="#00a660" style="transform:scale(0.7)" disabled :checked="notice.sysNotice == 1 ?true:false" v-model="notice.sysNotice" />
			</span>	
		</template>
	</uni-section>		
	<!-- 短信通知 -->
	<uni-section class="mb-10" title="短信通知" sub-title="若关闭，进行文件签署、文件签署完成时，将不通过短信的方式向您注册的手机发送通知短信。">
		<template v-slot:right>
			<span @click="handleSmsNoticeStatusChange(notice)">
				<switch color="#00a660" style="transform:scale(0.7)" disabled :checked="notice.smsNotice == 1 ?true:false" v-model="notice.smsNotice"/>
			</span>
		</template>
	</uni-section>
	<!-- 邮箱通知 -->
	<uni-section class="mb-10" title="邮箱通知" sub-title="若关闭，进行文件签署、文件签署完成时，将不通过邮件的方式向您注册的邮箱发送通知邮件。">
		<template v-slot:right>
			<span @click="handleEmailNoticeStatusChange(notice)">
				<switch color="#00a660" style="transform:scale(0.7)" disabled :checked="notice.emailNotice == 1 ?true:false" v-model="notice.emailNotice"/>
			</span>
		</template>
	</uni-section>
	<!-- 微信通知 -->
	<uni-section class="mb-10" title="微信通知" sub-title="若关闭，进行文件签署、文件签署完成时，将不通过微信的方式向您关注的公众号发送通知信息。">
		<template v-slot:right>
			<span @click="handleWechatNoticeStatusChange(notice)">
				<switch color="#00a660" style="transform:scale(0.7)" disabled :checked="notice.wechatNotice == 1 ?true:false" v-model="notice.wechatNotice"/>
			</span>
		</template>
	</uni-section>
	 </view>
	</uni-collapse-item>
	<uni-collapse-item title="提醒设置" >
		<view class="content">
	<uni-section class="mb-10" style="margin-top: 0;" title="签署截止日期">
		<template v-slot="subTitle">
			<view class="row-text">
				<span>提前</span>
				<uni-easyinput v-model="signEndDays" size="mini" maxlength="3" :disabled="notice.signEndNotice == 0? true : false" style="width:120rpx;padding:0 10rpx;display: inline-block;" :clearable="false" @blur="updateSignEndDays(signEndDays)"></uni-easyinput>
				<span>天，提醒您参与签署的文件即将超出签署截止日期。</span>
			</view>
		</template>
		<template v-slot:right>
			<span @click="handleSignEndNoticeStatusChange(notice)">
				<switch color="#00a660" style="transform:scale(0.7)" disabled :checked="notice.signEndNotice == 1 ?true:false" v-model="notice.signEndNotice"/>
			</span>
		</template>
	</uni-section>
	<uni-section class="mb-10" title="合同到期提醒">
		<template v-slot="subTitle">
			<view class="row-text">
				<span>提前</span>
				<uni-easyinput v-model="contractExpireDays" size="mini" maxlength="3" :disabled="notice.contractExpireNotice == 0? true : false" style="width:120rpx;padding:0 10rpx;display: inline-block;" :clearable="false" @blur="updateContractExpireDays(contractExpireDays)"></uni-easyinput>
				<span>天，提醒您参与签署的文件即将超出签署截止日期。</span>
			</view>
		</template>
		<template v-slot:right>
			<span @click="handleContractExpireNoticeStatusChange(notice)">
				<switch color="#00a660" style="transform:scale(0.7)" disabled :checked="notice.contractExpireNotice == 1 ?true:false" v-model="notice.contractExpireNotice"/>
			</span>
		</template>
	</uni-section>	
	 </view>
	</uni-collapse-item>
	  </uni-collapse>
  </view>
</template>

<script>
  import {getInfo, update} from "@/api/ec/person/user/systemSet";
  export default {
    data() {
      return {
		activeVal:['0'],
        // 系统设置参数
        notice: {},
        // 签署截止日期
        signEndDaysTipsShow: false,
        signEndDays: 0,
        // 合同到期提醒
        contractExpireDaysTipsShow: false,
        contractExpireDays: 0      
      }
    },
	created() {
	  this.getInfo();
	}, 
    methods: {
		/** 签署截止日期 */
		updateSignEndDays(signEndDays){
			if (signEndDays.length <= 0) {
			  this.signEndDays = this.notice.signEndDays;
				this.$modal.msgError("不能为空，最小是 1 ！");
			    return;
			  }
			  if (parseInt(signEndDays) == this.notice.signEndDays) {
			    return;
			  }
			  let id = this.notice.id;
			  const param = {id, signEndDays}
			  update(param).then(() => {
			    this.notice.signEndDays = parseInt(signEndDays);
			    this.$modal.msgSuccess("签署截止日期设置成功！");
			  }).catch(() => {
			    this.signEndDays = this.notice.signEndDays;
			  });      
		},
		/** 合同到期提醒 */
		updateContractExpireDays(contractExpireDays){
			if (contractExpireDays.length <= 0) {
			     this.contractExpireDays = this.notice.contractExpireDays;
				 this.$modal.msgError("不能为空，最小是 1 ！");
			     return;
			   }
			   if (parseInt(contractExpireDays) == this.notice.contractExpireDays) {
			     return;
			   }
			   let id = this.notice.id;
			   const param = {id, contractExpireDays}
			   update(param).then(() => {
			     this.notice.contractExpireDays = parseInt(contractExpireDays);
			     this.$modal.msgSuccess("合同到期提醒日期设置成功！");
			   }).catch(() => {
			     this.contractExpireDays = this.notice.contractExpireDays;
			   });     
		},
	  /** 查询消息设置信息 */
	  getInfo() {
      this.$modal.loading();
	    getInfo().then(response => {
		  uni.hideLoading()
	      this.notice = response.data;
	      this.signEndDays = response.data.signEndDays;
	      this.contractExpireDays = response.data.contractExpireDays;
	    });
	  },
	   /** 站内通知 */
	    handleSysNoticeStatusChange(data) {
	      let msg = (data.sysNotice === 0 ? "开启" : "关闭") + "站内通知";
	      let id = data.id;
		  let sysNotice = data.sysNotice === 1 ? 0 : 1;
	      const param = {id, sysNotice}
	      update(param).then(() => {
	        this.getInfo();
	        this.$nextTick(()=>{
	        	this.$modal.msgSuccess(msg + "成功！");
	        })
	      }).catch(function () {
	      });
	    },
	    /** 短信通知 */
	    handleSmsNoticeStatusChange(data) {
	      let msg = (data.smsNotice === 0 ? "开启" : "关闭") + "短信通知";
	      let id = data.id;
		  let smsNotice = data.smsNotice === 1 ? 0 : 1;
	      const param = {id, smsNotice}
	      update(param).then(() => {
	        this.getInfo();
	        this.$nextTick(()=>{
	        	this.$modal.msgSuccess(msg + "成功！");
	        })
	      }).catch(function () {
	      });
	    },
	    /** 邮箱通知 */
	    handleEmailNoticeStatusChange(data) {
	      let msg = (data.emailNotice === 0 ? "开启" : "关闭") + "邮箱通知";
	      let id = data.id;
	      let emailNotice = data.emailNotice === 1 ? 0 : 1;
	      const param = {id, emailNotice}
	      update(param).then(() => {
			this.getInfo();
			this.$nextTick(()=>{
				this.$modal.msgSuccess(msg + "成功！");
			})
	      }).catch(function () {
	      });
	    },
	    /** 微信通知 */
	    handleWechatNoticeStatusChange(data) {
	      let msg = (data.wechatNotice === 0 ? "开启" : "关闭") + "微信通知";
	      let id = data.id;
		  let wechatNotice = data.wechatNotice === 1 ? 0 : 1;
	      const param = {id, wechatNotice}
	      update(param).then(() => {
	        this.getInfo();
	        this.$nextTick(()=>{
	        	this.$modal.msgSuccess(msg + "成功！");
	        })
	      }).catch(function () {
	      });
	    },
		/** 签署截止日期 */
		handleSignEndNoticeStatusChange(data) {
		  let msg = (data.signEndNotice === 0 ? "开启" : "关闭") + "签署截止日期提示";
		  let id = data.id;
		  let signEndNotice = data.signEndNotice === 1 ? 0 : 1;
		  const param = {id, signEndNotice}
		  update(param).then(() => {
		   this.getInfo();
		   this.$nextTick(()=>{
		   	this.$modal.msgSuccess(msg + "成功！");
		   })
		  }).catch(function () {
		  });
		},
	    /** 合同到期提醒日期 */
	    handleContractExpireNoticeStatusChange(data) {
	      let msg = (data.contractExpireNotice === 0 ? "开启" : "关闭") + "合同到期提醒日期提示";
	      let id = data.id;
		  let contractExpireNotice = data.contractExpireNotice === 1 ? 0 : 1;
	      const param = {id, contractExpireNotice}
	      update(param).then(() => {
	        this.getInfo();
	        this.$nextTick(()=>{
	        	this.$modal.msgSuccess(msg + "成功！");
	        })
	      }).catch(function () {
	      });
	    }    
    }
  }
</script>

<style lang="scss" scoped>
	::v-deep .uni-collapse-item__wrap{background-color: #f5f6f7;}
	// 折叠面板修改
	::v-deep .uni-collapse-item__wrap {
		background-color: #f5f6f7;
	}
	
	::v-deep .uni-collapse-item__title {
		background-color: #f7f8fa;
	}
	
	::v-deep .uni-collapse-item__title-box {
		background-color:#f7f8fa;
	}
	
  ::v-deep .uni-section .uni-section-header{padding: 24rpx 32rpx;}
  ::v-deep .uni-noticebar{margin: 0; padding:14rpx 20rpx;}
  ::v-deep .uni-easyinput__content-input{height: 40rpx;}
  .mb-10{
		margin-top: 30rpx;
  }
  page {
    background-color: $uni-bg-color-grey;
  }
  .row-text{
	  padding:0 40rpx 20rpx 40rpx;
	  font-size: 22rpx;
	  color: #999999;
  }
  .help-container {
    margin-bottom: 100rpx;
  }
</style>
